<?php
/**
 * Created by PhpStorm.
 * User: wangwenfan
 * Date: 2018/8/29
 * Time: 19:06.
 */

namespace App\Admin\Controllers;

use App\Models\Base\LogNewGuide;
use App\Models\Base\ServerList;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class GuideController extends Controller
{
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('game.data_statistic'));
            $content->description(trans('game.new_user_task_state'));
            $content->body($this->grid());
        });
    }

    protected function grid()
    {
        return Admin::grid(LogNewGuide::class, function (Grid $grid) {
            $grid->date_time(trans('game.date'));
            $grid->server()->name(trans('game.server_name'));
            $grid->first_task_finish(trans('game.task_first_number'));
            $grid->first_task_undone(trans('game.not_task_first_number'));
            $grid->first_task_finish_wash(trans('game.task_first_number_rate'))->display(function ($first_finish) {
                return floatPercent($first_finish);
            });
            $grid->first_task_undone_wash(trans('game.task_not_first_number_rate'))->display(function ($undone_wash) {
                return floatPercent($undone_wash);
            });
            $grid->task_finish_all(trans('game.task_all_number'));
            $grid->task_finish_all_wash(trans('game.task_all_number_rate'))->display(function ($all_wash) {
                return floatPercent($all_wash);
            });
            $grid->disableActions();
            $grid->disableCreateButton();

            $grid->filter(function ($filter) {
                // 去掉默认的id过滤器
                $filter->disableIdFilter();
                $filter->equal('server_id', trans('game.server_name'))->select(ServerList::all()->pluck('name', 'server_id'));
            });
        });
    }
}
